package gatperdut.chato.core.interpreter.grammar.comminfo.indexedword;

public class IndexedWord {

    public enum RefType {
        OBJECT, ENTITY, UNKNOWN;
    };

    private final String word;

    private final int index; // #.word

    private int pos; // where it needs to be inserted

    private RefType refType = RefType.UNKNOWN;

    private String replacement = null;

    public IndexedWord( String word, int index, int pos ) {
        this.word = word;
        this.index = index;
        this.pos = pos;
    }

    public IndexedWord( String indexedWord, int pos ) {
        this.pos = pos;

        String[] parts = indexedWord.split( "\\." );

        if ( parts.length != 1 && parts.length != 2 ) {
            throw new IllegalArgumentException( "Bad indexed word format: '" + indexedWord + "'" );
        }

        if ( parts.length == 1 ) {
            this.index = 1;
            this.word = new String( indexedWord );
        }
        else {
            this.index = Integer.parseInt( parts[0] );
            this.word = new String( parts[1] );
        }
    }

    public String getWord() {
        return word;
    }

    public int getIndex() {
        return index;
    }

    public int getPos() {
        return pos;
    }

    public void setPos( int pos ) { // TODO always used to set a lower value. Create decreasePos(pos);
        this.pos = pos;
    }

    public RefType getRefType() {
        return refType;
    }

    public void setRefType( RefType refType ) {
        this.refType = refType;
    }

    public String getReplacement() {
        return replacement;
    }

    public void setReplacement( String replacement ) {
        this.replacement = replacement;
    }

}
